package com.iknow.ui.model;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.iknow.data.IKnowMessage;
import com.iknow.util.StringUtil;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class FriendChatAdapter extends BaseAdapter
{
  public static SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm");
  protected Context ctx = null;
  protected int fromId;
  private LayoutInflater inflater = null;
  private List<IKnowMessage> mMsgList = null;

  public FriendChatAdapter(Context paramContext)
  {
    this.ctx = paramContext;
    this.inflater = ((LayoutInflater)paramContext.getSystemService("layout_inflater"));
    this.mMsgList = new ArrayList();
  }

  public void addMessage(IKnowMessage paramIKnowMessage)
  {
    this.mMsgList.add(paramIKnowMessage);
  }

  public void bindView(IKnowMessage paramIKnowMessage, View paramView, int paramInt)
  {
    FriendViewHolder localFriendViewHolder;
    UserViewHolder localUserViewHolder;
    Object localObject = paramView.getTag();
    Date localDate = StringUtil.StrToDate(paramIKnowMessage.getRemoteTime());
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("MM-dd HH:mm");
    boolean bool = StringUtil.compareTime(localDate);
    if (localObject instanceof UserViewHolder)
    {
      localUserViewHolder = (UserViewHolder)localObject;
      localUserViewHolder.message.setText(paramIKnowMessage.getMsg());
      if (!(bool))
        break label130;
      localUserViewHolder.time.setText(sdf2.format(localDate));
    }
    if (localObject instanceof FriendViewHolder)
    {
      localFriendViewHolder = (FriendViewHolder)localObject;
      localFriendViewHolder.message.setText(paramIKnowMessage.getMsg());
      if (!(bool))
        break label148;
      localFriendViewHolder.time.setText(sdf2.format(localDate));
    }
    while (true)
    {
      while (true)
      {
        return;
        label130: localUserViewHolder.time.setText(localSimpleDateFormat.format(localDate));
      }
      label148: localFriendViewHolder.time.setText(localSimpleDateFormat.format(localDate));
    }
  }

  public int getCount()
  {
    int i;
    if (this.mMsgList != null)
      i = this.mMsgList.size();
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public IKnowMessage getItem(int paramInt)
  {
    return ((IKnowMessage)this.mMsgList.get(paramInt));
  }

  public long getItemId(int paramInt)
  {
    return paramInt;
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    View localView;
    IKnowMessage localIKnowMessage = getItem(paramInt);
    int i = Integer.parseInt(localIKnowMessage.getTypeID());
    if ((paramView == null) || (i == 0))
      localView = newUserView();
    while (true)
    {
      bindView(localIKnowMessage, localView, i);
      return localView;
      localView = newFriendView();
    }
  }

  public View newFriendView()
  {
    FriendViewHolder localFriendViewHolder = new FriendViewHolder(this);
    View localView = this.inflater.inflate(2130903086, null);
    localFriendViewHolder.message = ((TextView)localView.findViewById(2131296433));
    localFriendViewHolder.time = ((TextView)localView.findViewById(2131296288));
    localView.setTag(localFriendViewHolder);
    return localView;
  }

  public View newUserView()
  {
    UserViewHolder localUserViewHolder = new UserViewHolder(this);
    View localView = this.inflater.inflate(2130903089, null);
    localUserViewHolder.message = ((TextView)localView.findViewById(2131296433));
    localUserViewHolder.time = ((TextView)localView.findViewById(2131296288));
    localView.setTag(localUserViewHolder);
    return localView;
  }

  public void setMsgList(List<IKnowMessage> paramList)
  {
    this.mMsgList = paramList;
  }

  public class FriendViewHolder
  {
    TextView message;
    TextView time;
  }

  public class UserViewHolder
  {
    TextView message;
    TextView time;
  }
}